package com.example.javafx.gridPane;

import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        BorderPane root = new BorderPane();
        Scene scene = new Scene(root,380,150, Color.WHITE);

        GridPane gridPane = new GridPane();
        gridPane.setPadding(new Insets(5));
        gridPane.setHgap(5);
        gridPane.setVgap(5);

        ColumnConstraints column1 = new ColumnConstraints(100);
        ColumnConstraints column2 = new ColumnConstraints(50,150,300);
        column2.setHgrow(Priority.ALWAYS);
        gridPane.getColumnConstraints().addAll(column1,column2);

        Label fNameLbl = new Label("First Name");
        TextField fNameFld = new TextField();
        Label lNameLbl = new Label("Last Name");
        TextField lNameFld = new TextField();

        Button saveButt = new Button("Save");

        //First name label
        GridPane.setHalignment(fNameLbl, HPos.RIGHT);
        gridPane.add(fNameLbl,0,0);

        //Last name label
        GridPane.setHalignment(lNameLbl,HPos.RIGHT);
        gridPane.add(lNameLbl,0,1);

        //First name field
        GridPane.setHalignment(fNameFld,HPos.LEFT);
        gridPane.add(fNameFld,1,0);

        //Last name field
        GridPane.setHalignment(lNameFld,HPos.LEFT);
        gridPane.add(lNameFld,1,1);

        //save Button
        GridPane.setHalignment(saveButt,HPos.LEFT);
        gridPane.add(saveButt,1,2);

        root.setCenter(gridPane);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
